package com.wake.mycomposebook.ui.home.layouts.advlist.swpier

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import com.wake.carousel.Pager
import com.wake.carousel.PagerState
import com.wake.data.DemoDataProvider
import com.wake.data.model.Item

/**
 *@author created by WA03675
 *@date  2022-04-21 17:17
 *@des
 */

@Composable
fun MySwiper3() {
    Column(Modifier.verticalScroll(rememberScrollState())) {


        val items = remember {
            DemoDataProvider.itemList.take(5)
        }
        val pageState: PagerState = run {
            remember {
                PagerState(1, 0, items.size - 1)
            }
        }

        val selectIndex = remember {
            mutableStateOf(2)
        }

        MySwiper3Card1(items, pageState, selectIndex)

    }

}

@Composable
fun MySwiper3Card1(items: List<Item>, pageState: PagerState, selectIndex: MutableState<Int>) {
    Pager(state = pageState, modifier = Modifier.height(200.dp)) {
        val item = items[commingPage]
        selectIndex.value = currentPage
        MySwiper3Card1Item(item)
    }
}

@Composable
fun MySwiper3Card1Item(item: Item) {
    Box {
        Image(
            painter = painterResource(id = item.imageId),
            contentDescription = null,
            contentScale = ContentScale.Crop,
            modifier = Modifier
                .padding(4.dp)
                .fillMaxWidth()
                .clip(RoundedCornerShape(12.dp))
        )
    }
}

